//
//  UIBarButtonItem+Custom.m
//  SS-FXYX
//
//  Created by paycloud110 on 16/4/26.
//  Copyright © 2016年 paycloud110. All rights reserved.
//

#import "UIBarButtonItem+Custom.h"
#import "UIView+Size.h"

@implementation UIBarButtonItem (Custom)

+ (UIBarButtonItem *)barButtonItemWithTarget:(id)target andWithAction:(SEL)action andWithImage:(NSString *)image
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    button.size = button.currentBackgroundImage.size;
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}
+ (UIBarButtonItem *)barButtonItemWithTarget:(id)target andWithAction:(SEL)action andWithTitle:(NSString *)title selectedTitle:(NSString *)selectedTitle
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button setTitle:selectedTitle forState:UIControlStateSelected];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button sizeToFit];
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

@end
